package com.lagou.myblog.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.myblog.dao.TArticleMapper;
import com.lagou.myblog.domain.EasyUIBean;
import com.lagou.myblog.entity.TArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TArticleService {
    @Autowired
    private TArticleMapper articleMapper;

    public TArticle findOne(Integer id) {
        return articleMapper.selectByPrimaryKey(id);
    }

    public EasyUIBean queryAll(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize, "id asc");
        PageInfo<TArticle> pageInfo = new PageInfo<>(articleMapper.findByPage());
        return EasyUIBean.build(pageInfo.getTotal(), pageInfo.getList());
    }

    public TArticle saveBean(TArticle bean) {
        articleMapper.insert(bean);
        return bean;
    }

    public TArticle updateBean(TArticle bean) {
        articleMapper.updateByPrimaryKey(bean);
        return bean;
    }

    public void deleteBean(Integer id) {
        articleMapper.deleteByPrimaryKey(id);
    }

}
